package com.geilizu.dom.controller;

import com.geilizu.dom.dto.SearchDto;
import com.geilizu.dom.entity.Moveout;
import com.geilizu.dom.result.ResponseCode;
import com.geilizu.dom.result.ResponseData;
import com.geilizu.dom.service.MoveoutService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * (Moveout)表控制层
 *
 * @author makejava
 * @since 2022-07-12 23:40:23
 */
@RestController
@RequestMapping("moveout")
public class MoveoutController {
    /**
     * 服务对象
     */
    @Resource
    private MoveoutService moveoutService;

    @GetMapping("/moveoutList/{page}/{size}")
    public ResponseData moveoutList(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
        Map<String, Object> map = moveoutService.moveoutList(page, size);
        return new ResponseData("200", "success", (Long) map.get("count"), map.get("moveoutList"));
    }

    @PostMapping("/moveoutSearch")
    public ResponseData search(@RequestBody SearchDto searchDto) {
//        System.out.println(searchDto.getKey());
        Map<String, Object> map = moveoutService.search(searchDto);
        return new ResponseData("200", "success", (Long) map.get("count"), map.get("moveoutList"));
    }

    @GetMapping("/list/{page}/{size}")
    public ResponseData list(@PathVariable("page") Integer page, @PathVariable("size") Integer size){
        Map<String, Object> map = moveoutService.list(page,size);
        return new ResponseData("200", "success", (Long) map.get("count"), map.get("moveList"));
    }

    @PostMapping("/search")
    public ResponseData stuSearch(@RequestBody SearchDto searchDto) {
//        System.out.println(searchDto.getKey());
        Map<String, Object> map = moveoutService.stuSearch(searchDto);
        return new ResponseData("200", "success", (Long) map.get("count"), map.get("stuList"));
    }

    @PutMapping("/moveout/{id}/{reason}")
    public ResponseData moveout(@PathVariable("id") Integer id,@PathVariable("reason") String reason){
        Integer moveout = moveoutService.moveout(id, reason);
        if(moveout>0){
            return new ResponseData(ResponseCode.SUCCESS);
        }else{
            return new ResponseData(ResponseCode.FAILED);
        }
    }

    @DeleteMapping("/deleteById/{id}")
    public ResponseData deleteById(@PathVariable("id") Integer id){
        Integer i= moveoutService.deleteById(id);
        if(i>0){
            return new ResponseData(ResponseCode.SUCCESS);
        }else{
            return new ResponseData(ResponseCode.FAILED);
        }
    }

}

